/**
 * dialog창을 변경없이 dialog 설정하는 class이다.
 */
InnerWindow =function (){
        var builder= function() 
		{
			    var mainW  =  document.createElement('div'); //dialog main
			    var cont =  document.createElement('div');  // 내용이 들어갈 블럭
			    var close =  document.createElement('div'); // close버튼
			    var title ;
			    var bgcolor,contbgcolor;
			    var parentElem ; // mainW를 추가할 부모 tag
			    var contents ;  // 가변적인 들어갈 내용들
			    var that = this;
			    var opacity=0; //투명도 설정
		    this.setSize=function(headerTitle,width , height)
			{
				mainW.style.width = width;
				mainW.style.height = height;
				this.title = headerTitle;
				return this;
			};
			this.setParentElem= function(id)
			{
				//console.log('setParentElem ' +id);
				this.parentElem = id;
				return this;
			};
			
			this.setHeaderBgColor=function( bgcolor)
			{
				this.bgcolor= bgcolor;
				return this;
			};
			this.setContentBgColor=function( bgcolor)
			{
				this.contbgcolor= bgcolor;
				return this;
			};
			this.setContentBgColor=function( bgcolor)
			{
				this.contbgcolor= bgcolor;
				return this;
			};
			/**
			 * 투명도 설정 main back
			 * 0~1.0
			 */
			this.setOpacity= function(value)
			{
				 this.opacity=value;
			}
			
			

			/**
			 * 본문 내용을 들어갈 html
			 */
			this.setContent=function(html)
			{
				this.contents = html;
				return this;
		    };
		    
		  
			// build pattern으로 위의 변경 내용을 적용하여 dialog를 생성한다.
			this.createWindow=function()
			{	
				mainW.setAttribute('id',"wdialog")  ;
				
			    var x =WinLoc.getCenterX(mainW);
			    var y =WinLoc.getCenterY(mainW);
			
				mainW.style.left = x +"px";
				mainW.style.top = y +"px";
				console.log('loc =>'+ x + "  " + y + ' ' + document.body.clientHeight );

				
				var html= new Array();
				html.push('<div id=\'wheader\' class="inbox">');
				html.push(this.title);
				html.push('</div>');
				html.push('<div id=\'close\' class="inbox">X</div>');
				html.push('<div style=\'float:clear\'></div>');
				cont.innerHTML =this.contents ;
				mainW.innerHTML=html.join('');
				mainW.appendChild(cont);
				mainW.style.border="1px solid blue";
				this.parentElem.innerHTML=""; //CLEAR
				this.parentElem.appendChild(mainW);
				this.parentElem.style.display='block';
				this.parentElem.style.opacity= that.opacity;	
				
				
				
				//return mainW;
				setEvent();
				return this.parentElem;
			};
				      
			
			var setEvent = function()
					{
						var nodes = mainW.getElementsByTagName("div");
						for (var i=0;i < nodes.length; i++)
						{	
							if ('close' ==nodes[i].getAttribute('id'))
							{
								 if (  nodes[i].addEventListener)
								 {
		    							 nodes[i].addEventListener('click',function()
										{
												
											that.parentElem.style.display='none';
										});
								 } else
								 { 
									nodes[i].attachEvent('onclick',function()
									{
										
										that.parentElem.style.display='none';
									}) ;
								 }
							 
							}
						}
						
					};
			
		};
		
		this.build = new builder();
};
